package com.sw.controller;

import com.sw.pojo.Article;
import com.sw.pojo.PageBean;
import com.sw.pojo.Result;
import com.sw.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;


    @PostMapping("add")
    public Result add(@RequestBody @Validated Article article) {
        articleService.add(article);
        return Result.success();
    }

    @GetMapping("/listPage")
    public Result<PageBean<Article>> list(Integer page, Integer pageSize,
                                          @RequestParam(required = false) String categoryId,
                                          @RequestParam(required = false) String state) {
        return Result.success(articleService.list(page, pageSize, categoryId, state));
    }
}
